<%@ page contentType="text/html; charset=UTF-8" language="java" import="com.pub.tools.*,com.pub.database.*,java.util.*" %>
<%
   ArrayList<ArrayList<Object>> altDeptList = null;
   ArrayList<Object> altTopDept = null;
   ArrayList<Object> altDeptListData = null;
   QueryBean qbnDAO=null;
   String lstrDBAlias=request.getParameter("DB_ALIAS");
   String lstrDBDebug=request.getParameter("DEBUG");
   String lstrSrcCharset=request.getParameter("SOURCE_CHARSET");
   String lstrTgrCharset=request.getParameter("TARGET_CHARSET");
   StringBuffer lstbClickAction=new StringBuffer();

   try{

     qbnDAO=new QueryBean(lstrDBAlias,Boolean.valueOf(lstrDBDebug).booleanValue(),lstrSrcCharset,lstrTgrCharset);

     StringBuffer stbSQL=new StringBuffer("select dept_name,dept_no,dept_up, level as floor from bas_dept ");
     stbSQL.append("where dept_status='Y' ");
     stbSQL.append("group by level,dept_no,dept_up,dept_name ");
     stbSQL.append("start with dept_up = '" + request.getParameter("deptup") + "' connect by prior dept_no = dept_up ");

     altDeptList=qbnDAO.querySQL(stbSQL.toString());

     altTopDept=(ArrayList<Object>)qbnDAO.querySQL("select dept_name,dept_no from bas_dept where dept_no='" + request.getParameter("deptup") + "'").get(0);

     if(request.getParameter("prgAction")!=null && request.getParameter("prgAction").equals("getDept")){
       lstbClickAction.append("javascript:window.returnValue=%dept%");
     }
     else{
       lstbClickAction.append("EmployeeList.jsp?");

       lstbClickAction.append("DB_ALIAS=");
       lstbClickAction.append(lstrDBAlias);
       lstbClickAction.append("&DEBUG=");
       lstbClickAction.append(lstrDBDebug);
       lstbClickAction.append("&SOURCE_CHARSET=");
       lstbClickAction.append(lstrSrcCharset);
       lstbClickAction.append("&TARGET_CHARSET=");
       lstbClickAction.append(lstrTgrCharset);
       lstbClickAction.append("&deptno=%dept%");
     }
%>
<html>

<head>
   <meta http-equiv="Content-Type" content="text/html; charset=big5"/>
   <script language="javascript" type="" src="general/ua.js"></script>
   <script language="javascript" type="" src="general/ftiens4.js"></script>
   <script language="javascript" type="">
     function reloadEmp(varDeptno){
       window.open("EmployeeList?deptno="+varDeptno,"right");
     }
   </script>
   <script language="javascript" type="">
     USETEXTLINKS = 1;
     STARTALLOPEN = 0;
     ICONPATH='pub_images/menutree/';
     USEICONS = 0;
     foldersTree = gFld('<%=altTopDept.get(0).toString()%>',"<%=lstbClickAction.toString().replaceAll("%dept%",altTopDept.get(1).toString())%>");
     //alert(foldersTree);
     var folderObj;

      <%
        if(altDeptList !=null && !altDeptList.isEmpty()){
          for(int i=0;i<altDeptList.size();i++){
            altDeptListData=((ArrayList<Object>)altDeptList.get(i));
            if(altDeptListData.get(3).toString().equals("1")){
              out.println("DEPT" + altDeptListData.get(1).toString() + "=insFld(foldersTree,gFld(\"" + altDeptListData.get(0).toString() + "\",\"" + lstbClickAction.toString().replaceAll("%dept%",altDeptListData.get(1).toString()) + "\"));");
            }
            else{
              out.println("DEPT" + altDeptListData.get(1).toString() + " = insFld(DEPT" + altDeptListData.get(2).toString() + ", gFld(\"" + altDeptListData.get(0).toString() + "\",\"" + lstbClickAction.toString().replaceAll("%dept%",altDeptListData.get(1).toString()) + "\"));");
            }
          }
        }
      %>
   </script>
   <title></title>
</head>
<base target='_self'/>
<body>

<SPAN STYLE="DISPLAY='none'">
  <a href="http://www.treemenu.net/" target="_blank">km</a>
</span>
<%if((altDeptList !=null && !altDeptList.isEmpty())||(altTopDept !=null && !altTopDept.isEmpty())){out.println("<script>initializeDocument()</script>");}%>
</body>
</html>
<%
   }
   catch(Exception e){
     e.printStackTrace();
   }
   finally{
     try{qbnDAO.close();}catch(Exception e){System.out.println("無法關閉QueryBean's Connection in EmployeeList.jsp");}
     qbnDAO=null;

     if(altDeptList !=null && !altDeptList.isEmpty()){
       altDeptListData.clear();
       altDeptList.clear();
     }

     if(!altTopDept.isEmpty()){
       altTopDept.clear();
     }

     altDeptListData=null;
     altDeptList=null;
     altTopDept=null;
   }
%>
